using System;
using System.Collections.Generic;
using System.Text;

namespace Tortuga.Core.TortoiseCommands {
	/// <summary>
	/// Launches the log window for the specified file. 
	/// "Opens the log dialog. The path specifies the file or folder for which the log should be shown. Three additional options can be set: /revstart:xxx, /revend:xxx and /strict"
	/// http://tortoisesvn.net/docs/nightly/TortoiseSVN_en/apc.html
	/// </summary>
	public class LogCommand : RevisionRangeTortoiseCommand {
		private bool _strict = false;
		private string _path = "";

		public LogCommand()
			: base("log") {
			this.OptionsToBuild = new List<BuildOptionDelegate>();
			this.OptionsToBuild.AddRange(new BuildOptionDelegate[] {
				this.BuildPathOption,
				this.BuildRevisionStartOption,
				this.BuildRevisionEndOption,
				this.BuildNoTempFile,
				this.BuildCloseOnEnd
			});
		}

		/// <summary>
		/// Instantiates a LogCommand with no start or end revision.
		/// </summary>
		/// <param name="path"></param>
		public LogCommand(string path)
			: this() {
			this.Path = path;
		}
		
		/// <summary>
		/// Instantiates a LogCommand with a specified start and end revision and strict value.
		/// </summary>
		/// <param name="path">The path to the file to view the log for.</param>
		/// <param name="start">The first revision of this file to view log for.</param>
		/// <param name="end">The last revision of this file to view log for.</param>
		/// <param name="strict"></param>
		public LogCommand(string path, Revision start, Revision end, bool strict)
			: this(path) {
			this.RevisionStart = start;
			this.RevisionEnd = end;
			this.Strict = strict;
		}
		/// <summary>
		/// Gets or sets the path of the file for whose log to view.
		/// </summary>
		public new string Path {
			get { return _path; }
			set { _path = value; }
		}

		public bool Strict {
			get { return _strict; }
			set { _strict = value; }
		}

		/// <summary>
		/// Builds a Strict command.
		/// </summary>
		/// <param name="strict"></param>
		/// <returns>/strict</returns>
		public static string BuildStrictCommand(bool strict) {
			return BuildOption("strict", strict);
		}

		/// <summary>
		/// Builds a Strict command.
		/// </summary>
		/// <param name="strict"></param>
		/// <returns>/strict</returns>
		public string BuildStrictCommand() {
			return BuildStrictCommand(this.Strict);
		}

		public override string BuildPathOption() {
			return BuildPathOption(PathDelimiter, this.Path);
		}
	}
}
